<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>

  <script>
    /* 
    理解catch方法
      本质是then方法专门用来指定失败回调的语法糖(简洁语法)
      catch(onRejected) 相当于: then(value => value, onRejected)
        如果前面是成功的promise, catch返回成功的promise => 将成功promise向下传递
        如果前面是失败的promise, catch返回的promise由它指定的回调执行的结果决定
    */

    new Promise((resolve, reject) => {
      // reject(1)
      resolve(2)
    }).catch(reason => {
      console.log('1')
    }).then(value => {
      console.log('2', value)
    })

    // new Promise((resolve, reject) => {
    //   // reject(1)
    //   resolve(2)
    // })
    // .then(
    //   value => value,
    //   reason => {
    //     console.log('1')
    //   }
    // )

    new Promise((resolve, reject) => {
      reject(1)
      // resolve(2)
    }).catch(reason => {
      console.log('1')
    }).then(value => {
      console.log('2')
    })

  </script>
</body>
</html>